﻿using WeDonekRpc.Helper;

namespace Basic.UserFormService.Calculate.Extend
{
    public static class TimeExtend
    {
        private static readonly string[] _ZhWeek = new string[]
        {
            "星期天",
            "星期一",
            "星期二",
            "星期三",
            "星期四",
            "星期五",
            "星期六",
        };
        public static DateTime ParseTime ( string str )
        {
            return Tools.PaseDateTime(str);
        }
        public static DateTime Now ()
        {
            return DateTime.Now;
        }
        public static DateTime AddDay ( DateTime time, int day )
        {
            return time.AddDays(day);
        }
        public static DateTime Date ( DateTime time )
        {
            return time.Date;
        }
        public static string Format ( DateTime time, string format )
        {
            return time.ToString(format);
        }
        public static int Hour ( DateTime time )
        {
            return time.Hour;
        }
        public static int Second ( DateTime time )
        {
            return time.Second;
        }
        public static int Minute ( DateTime time )
        {
            return time.Minute;
        }
        public static int Year ( DateTime time )
        {
            return time.Year;
        }
        public static int Month ( DateTime time )
        {
            return time.Month;
        }
        public static int Day ( DateTime time )
        {
            return time.Day;
        }
        public static string DayOfWeek ( DateTime time, string lang = "zh" )
        {
            if ( lang == "zh" )
            {
                return _ZhWeek[(int)time.DayOfWeek];
            }
            return time.DayOfWeek.ToString();
        }
        public static int DayOfYear ( DateTime time )
        {
            return time.DayOfYear;
        }
        public static int DateDif ( DateTime one, DateTime two, string format )
        {
            if ( format == "y" )
            {
                return two.Year - one.Year;
            }
            else if ( format == "M" )
            {
                return ( ( two.Year - one.Year ) * 12 ) + ( two.Month - one.Month );
            }
            else if ( format == "d" )
            {
                return ( two - one ).Days;
            }
            else if ( format == "h" )
            {
                return ( two - one ).Hours;
            }
            else if ( format == "m" )
            {
                return ( two - one ).Minutes;
            }
            return ( two - one ).Seconds;
        }
    }
}
